'use strict';

/**
 * @ngdoc function
 * @name jgappApp.controller:TaskMytaskCtrl
 * @description
 * # TaskMytaskCtrl
 * Controller of the jgappApp
 */
angular.module('jgappApp')
    .controller('TaskMytaskCtrl', function(openApi, DataService, $location) {
        // 初始化
        this.subtabindex = 0;
        this.headertabindex = 0;
        // 初始化过程
        this.subtabList = [{
            value: "未开始",
            key: "willList"
        }, {
            value: "进行中",
            key: "beDoingList"
        }, {
            value: "已完成",
            key: "haveDoneList"
        }];
        this.headtabList = [{
            value: "我的任务",
            key: "willList"
        }, {
            value: "他人任务",
            key: "beDoingList"
        }];
        this.submenuhandle = function(index) {
            if (this.subtabindex == index) {
                return
            }
            this.subtabindex = index;
            if (this.taskdata) {
                var key = this.subtabList[this.subtabindex].key
                this.list1 = this.taskdata[key + "1"]
                this.list2 = this.taskdata[key + "2"]
                this.list3 = this.taskdata[key + "3"]
                this.list1page = this.taskdata[key + "1PageSize"]
                this.list2page = this.taskdata[key + "2PageSize"]
                this.list3page = this.taskdata[key + "3PageSize"]
            }
        }
        this.headermenuhandle = function(index) {
            if (this.headertabindex == index) {
                return
            }
            this.headertabindex = index;
            this.initData(index + 1);
        }
        this.headermenuhandle(0)
        this.initData = function(flag) {
            var param = {}
            param.flag = flag
            param.limit = 5
            DataService.getData(openApi.getMyTask, param).then(function(data) {
                this.taskdata = data
                this.list1 = this.taskdata.willList1
                this.list2 = this.taskdata.willList2
                this.list3 = this.taskdata.willList3
                this.submenuhandle(0)
            }.bind(this))

        };
        this.getPageType = function(type) {
            var pagetype;
            if (this.headertabindex == 0) {
                if (type == 1) {
                    switch (this.subtabindex) {
                        case 0:
                            pagetype = 1;
                            break;
                        case 1:
                            pagetype = 5;
                            break;
                        case 2:
                            pagetype = 9;
                            break;
                    }
                } else if (type == 2) {
                    switch (this.subtabindex) {
                        case 0:
                            pagetype = 2;
                            break;
                        case 1:
                            pagetype = 6;
                            break;
                        case 2:
                            pagetype = 10;
                            break;
                    }

                } else if (type == 3) {
                    switch (this.subtabindex) {
                        case 0:
                            pagetype = 4;
                            break;
                        case 1:
                            pagetype = 8;
                            break;
                        case 2:
                            pagetype = 12;
                            break;
                    }

                }

            } else if (this.headertabindex == 1) {
                switch (this.subtabindex) {
                    case 0:
                        pagetype = 3;
                        break;
                    case 1:
                        pagetype = 7;
                        break;
                    case 2:
                        pagetype = 11;
                        break;
                }

            }
            return pagetype
        };
        this.initData(1);
        this.goDetail = function(item) {
            var param = {}
            param.refId = item.pkId;
            DataService.getData(openApi.hasSeenByWorktask, param).then(function(data) {}.bind(this))
            $location.path("task/taskdetail/" + item.pkId)
        }
        this.gotasklist = function(type) {
            var pagetype;
            pagetype = this.getPageType(type)
            $location.path("task/mytasklist/" + pagetype)
        }
        this.createTask = function() {
            $location.path("task/newtask")
        }
    });
